// Copyright 2013 The Flutter Authors. All rights reserved.
// Copyright 2023 OutdatedGuy. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
import 'package:flutter/material.dart';

void main() {
  setUpAll(() async {
    TestWidgetsFlutterBinding.ensureInitialized();
  });

  group('CachedVideoPlayerPlusValue', () {
    test('uninitialized constructor', () {
      final value = const CachedVideoPlayerPlusValue.uninitialized();
      expect(value.isInitialized, false);
      expect(value.duration, Duration.zero);
    });

    test('erroneous constructor', () {
      final value = const CachedVideoPlayerPlusValue.erroneous('test error');
      expect(value.hasError, true);
      expect(value.errorDescription, 'test error');
      expect(value.isInitialized, false);
    });

    test('aspectRatio calculation', () {
      final value = CachedVideoPlayerPlusValue(
        duration: const Duration(seconds: 10),
        size: const Size(1920, 1080),
        isInitialized: true,
      );
      expect(value.aspectRatio, 1920 / 1080);
    });

    test('aspectRatio when not initialized', () {
      final value = const CachedVideoPlayerPlusValue.uninitialized();
      expect(value.aspectRatio, 1.0);
    });

    test('copyWith method', () {
      final original = CachedVideoPlayerPlusValue(
        duration: const Duration(seconds: 10),
        size: const Size(1920, 1080),
        position: const Duration(seconds: 5),
        isInitialized: true,
        isPlaying: false,
      );

      final copy = original.copyWith(
        isPlaying: true,
        position: const Duration(seconds: 6),
      );

      expect(copy.isPlaying, true);
      expect(copy.position, const Duration(seconds: 6));
      expect(copy.duration, original.duration);
      expect(copy.size, original.size);
    });
  });

  group('Caption', () {
    test('none caption', () {
      expect(Caption.none.text, '');
      expect(Caption.none.start, Duration.zero);
      expect(Caption.none.end, Duration.zero);
    });

    test('caption equality', () {
      final caption1 = Caption(
        number: 1,
        start: const Duration(seconds: 1),
        end: const Duration(seconds: 3),
        text: 'Hello',
      );

      final caption2 = Caption(
        number: 1,
        start: const Duration(seconds: 1),
        end: const Duration(seconds: 3),
        text: 'Hello',
      );

      final caption3 = Caption(
        number: 2,
        start: const Duration(seconds: 1),
        end: const Duration(seconds: 3),
        text: 'Hello',
      );

      expect(caption1, caption2);
      expect(caption1, isNot(caption3));
    });
  });

  group('Cache Management', () {
    test('removeFileFromCache method exists', () {
      expect(CachedVideoPlayerPlusController.removeFileFromCache, isA<Function>());
    });

    test('clearAllCache method exists', () {
      expect(CachedVideoPlayerPlusController.clearAllCache, isA<Function>());
    });
  });
}